package com.java110.mall.goods.smo.impl;


import com.java110.dto.housekeeping.HousekeepingServDto;
import com.java110.intf.goods.IHousekeepingServInnerServiceSMO;
import com.java110.mall.goods.dao.IHousekeepingServServiceDao;
import com.java110.po.housekeeping.HousekeepingServPo;
import com.java110.utils.util.BeanConvertUtil;
import com.java110.core.base.smo.BaseServiceSMO;
import com.java110.dto.PageDto;
import com.java110.utils.util.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @ClassName FloorInnerServiceSMOImpl
 * @Description 服务管理内部服务实现类
 * @Author wuxw
 * @Date 2019/4/24 9:20
 * @Version 1.0
 * add by wuxw 2019/4/24
 **/
@RestController
public class HousekeepingServInnerServiceSMOImpl extends BaseServiceSMO implements IHousekeepingServInnerServiceSMO {

    @Autowired
    private IHousekeepingServServiceDao housekeepingServServiceDaoImpl;


    @Override
    public int saveHousekeepingServ(@RequestBody HousekeepingServPo housekeepingServPo) {
        int saveFlag = 1;
        housekeepingServServiceDaoImpl.saveHousekeepingServInfo(BeanConvertUtil.beanCovertMap(housekeepingServPo));
        return saveFlag;
    }

     @Override
    public int updateHousekeepingServ(@RequestBody  HousekeepingServPo housekeepingServPo) {
        int saveFlag = 1;
         housekeepingServServiceDaoImpl.updateHousekeepingServInfo(BeanConvertUtil.beanCovertMap(housekeepingServPo));
        return saveFlag;
    }

     @Override
    public int deleteHousekeepingServ(@RequestBody  HousekeepingServPo housekeepingServPo) {
        int saveFlag = 1;
        housekeepingServPo.setStatusCd("1");
        housekeepingServServiceDaoImpl.updateHousekeepingServInfo(BeanConvertUtil.beanCovertMap(housekeepingServPo));
        return saveFlag;
    }

    @Override
    public List<HousekeepingServDto> queryHousekeepingServs(@RequestBody  HousekeepingServDto housekeepingServDto) {

        //校验是否传了 分页信息

        int page = housekeepingServDto.getPage();

        if (page != PageDto.DEFAULT_PAGE) {
            housekeepingServDto.setPage((page - 1) * housekeepingServDto.getRow());
        }
        Map productMap = BeanConvertUtil.beanCovertMap(housekeepingServDto);
        if(null != housekeepingServDto.getCreateTime() && !"".equals( housekeepingServDto.getCreateTime() )){
            productMap.put( "createTime", DateUtil.getFormatTimeString( housekeepingServDto.getCreateTime(), DateUtil.DATE_FORMATE_STRING_B) );
        }
        List<HousekeepingServDto> housekeepingServs = BeanConvertUtil.covertBeanList(housekeepingServServiceDaoImpl.getHousekeepingServInfo(productMap), HousekeepingServDto.class);

        return housekeepingServs;
    }

    @Override
    public List<HousekeepingServDto> searchHousekeepingServs(@RequestBody  HousekeepingServDto housekeepingServDto) {

        //校验是否传了 分页信息

        int page = housekeepingServDto.getPage();

        if (page != PageDto.DEFAULT_PAGE) {
            housekeepingServDto.setPage((page - 1) * housekeepingServDto.getRow());
        }

        List<HousekeepingServDto> housekeepingServs = BeanConvertUtil.covertBeanList(housekeepingServServiceDaoImpl.getSearchHousekeepingServInfo(BeanConvertUtil.beanCovertMap(housekeepingServDto)), HousekeepingServDto.class);

        return housekeepingServs;
    }


    @Override
    public int queryHousekeepingServsCount(@RequestBody HousekeepingServDto housekeepingServDto) {
        Map productMap = BeanConvertUtil.beanCovertMap(housekeepingServDto);
        if(null != housekeepingServDto.getCreateTime() && !"".equals( housekeepingServDto.getCreateTime() )){
            productMap.put( "createTime", DateUtil.getFormatTimeString( housekeepingServDto.getCreateTime(), DateUtil.DATE_FORMATE_STRING_B) );
        }
        return housekeepingServServiceDaoImpl.queryHousekeepingServsCount(productMap);    }

    public IHousekeepingServServiceDao getHousekeepingServServiceDaoImpl() {
        return housekeepingServServiceDaoImpl;
    }

    public void setHousekeepingServServiceDaoImpl(IHousekeepingServServiceDao housekeepingServServiceDaoImpl) {
        this.housekeepingServServiceDaoImpl = housekeepingServServiceDaoImpl;
    }
}
